package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.CCampFacility;
import com.ruoyi.wechat.domain.CFacility;
import com.ruoyi.wechat.domain.CFacilityType;
import com.ruoyi.wechat.mapper.CCampFacilityMapper;
import com.ruoyi.wechat.mapper.CFacilityMapper;
import com.ruoyi.wechat.service.IWxCFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxCFacilityServiceImpl implements IWxCFacilityService {
    @Autowired
    private CFacilityMapper cFacilityMapper;

    @Autowired
    private CCampFacilityMapper cCampFacilityMapper;

    @Override
    public CFacility selectCFacilityByFacilityId(String facilityId) {
        return cFacilityMapper.selectCFacilityByFacilityId(facilityId);
    }

    @Override
    public int insertCFacility(CFacility cFacility) {
        cFacility.setFacilityId(IdUtils.randomUUID());
        return cFacilityMapper.insertCFacility(cFacility);
    }
    @Override
    public int insertCFacility(String campId, String[] facilityIds) {
        //先删除营地下的服务设施
        cCampFacilityMapper.deleteCCampFacilityByCfId(campId);
        //然后插入新的服务设施
        for (String facilityId : facilityIds) {
            CCampFacility cCampFacility = new CCampFacility();
            cCampFacility.setCfId(IdUtils.randomUUID());
            cCampFacility.setCampId(campId);
            cCampFacility.setFacilityId(facilityId);
            cCampFacilityMapper.insertCCampFacility(cCampFacility);
        }
        return 1;
    }

    @Override
    public List<CFacilityType> campFacilityListByCampId(String campId) {
        //return campFacilityMapper.selectCampFacilityByCampId(campId);
        return cFacilityMapper.selectFaciliatyTypeAndFacilityListByCampId(campId);
    }
    @Override
    public int updateCFacility(CFacility cFacility) {
        return cFacilityMapper.updateCFacility(cFacility);
    }

    @Override
    public int deleteCFacilityByFacilityIds(String[] facilityIds) {
        return cFacilityMapper.deleteCFacilityByFacilityIds(facilityIds);
    }

    @Override
    public int deleteCFacilityByFacilityId(String facilityId) {
        return cFacilityMapper.deleteCFacilityByFacilityId(facilityId);
    }

    //    微信查询设施类型以及对应的所有设施
    @Override
    public List<CFacilityType> selectCFacilityByFacilityTypeId(CFacilityType cFacilityType)
    {
        return cFacilityMapper.selectCFacilityTypeAndFacilityList(cFacilityType);
    }
}
